home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / sdi / control.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-08  |  8.9 KB  |  293 lines

  1. /*****************************  control.c  ******************************/
  2. #include "sdi.h"
  3. #include <sunwindow/notify.h>
  4.  
  5. /*
  6.  * Copyright 1987 by Mark Weiser.
  7.  * Permission to reproduce and use in any manner whatsoever on Suns is granted
  8.  * so long as this copyright and other identifying marks of authorship
  9.  * in the code and the game remain intact and visible.  Use of this code
  10.  * in other products is reserved to me--I'm working on Mac and IBM versions.
  11.  */
  12.  
  13. /*
  14.  * The main code for setting up the control panel lives here.
  15.  * Other panel-related code is in control_procs.c, helpers.c, and main.c.
  16.  */
  17.  
  18. static short i_pic_array[] = {
  19. #include "interceptor_picture.h"
  20. };
  21. mpr_static(interceptor_pic, 16, 16, 1, i_pic_array);
  22.  
  23. static short l_pic_array[] = {
  24. #include "laser_picture.h"
  25. };
  26. mpr_static(laser_pic, 16, 16, 1, l_pic_array);
  27.  
  28. static short r_pic_array[] = {
  29. #include "rock_picture.h"
  30. };
  31. mpr_static(rock_pic, 16, 16, 1, r_pic_array);
  32.  
  33. static short f_pic_array[] = {
  34. #include "foe_picture.h"
  35. };
  36. mpr_static(foe_pic, 16, 16, 1, f_pic_array);
  37.  
  38. static short c1_pic_array[] = {
  39. #include "cursor.h"
  40. };
  41. mpr_static(normal_pic, 16, 16, 1, c1_pic_array);
  42.  
  43. static short c2_pic_array[] = {
  44. #include "dyna_picture.h"
  45. };
  46. mpr_static(dyna_pic, 16, 16, 1, c2_pic_array);
  47.  
  48. static short c3_pic_array[] = {
  49. #include "cross_picture.h"
  50. };
  51. mpr_static(cross_pic, 16, 16, 1, c3_pic_array);
  52.  
  53. static short c4_pic_array[] = {
  54. #include "silly_picture.h"
  55. };
  56. mpr_static(silly_pic, 16, 16, 1, c4_pic_array);
  57.  
  58. extern void next_round_proc(), quit_proc(), master_proc(), no_events(),
  59.     suspend_proc(), resume_proc(), open_proc(), scores_proc(), end_proc(),
  60.     help_proc(), about_proc(), higher_proc(), cycle_time_proc(),
  61.     save_proc(), restore_proc(), text_options_proc(), instructions_proc(),
  62.     cursor_notify_proc(), icon_option_proc(), misc_options_proc(),
  63.     ballistic_time_proc(), new_game_proc(), non_stop_notify_proc(),
  64.     version_proc();
  65. extern Panel_setting save_file_notify_proc(), name_notify_proc();
  66.  
  67. Panel_item cycle_time_item, timeout_item;
  68.  
  69. /*
  70.  * Build and place all the items in the control panel.
  71.  */
  72. init_control(panel)
  73. Panel panel;
  74. {
  75.     extern Panel_item rock_item;
  76.     extern int gamemaster, continuous, time_to_play, starting_skill;
  77.     extern struct pixfont *bigfont, *buttonfont; /* use 'struct pixfont', not 'Pixfont',
  78.                                              for 3.0 compatibility */
  79.     if ((bigfont = (struct pixfont *)pf_open(
  80.         "/usr/lib/fonts/fixedwidthfonts/screen.b.14")) == NULL) {
  81.             bigfont = (struct pixfont *)pf_default();
  82.     }
  83.     if ((buttonfont = (struct pixfont *)pf_open(
  84.         "/usr/lib/fonts/fixedwidthfonts/screen.r.12")) == NULL) {
  85.             buttonfont = (struct pixfont *)pf_default();
  86.     }
  87.     next_round_item = panel_create_item(panel, PANEL_BUTTON,
  88.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Next Round", 12, buttonfont),
  89.         PANEL_NOTIFY_PROC, next_round_proc,
  90.         PANEL_SHOW_ITEM, FALSE,
  91.         0);
  92.     (void) panel_create_item(panel, PANEL_BUTTON,
  93.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Quit", 6, buttonfont),
  94.         PANEL_NOTIFY_PROC, quit_proc,
  95.         0);
  96.     (void) panel_create_item(panel, PANEL_BUTTON,
  97.         PANEL_LABEL_IMAGE, panel_button_image(panel, "New Game", 10, buttonfont),
  98.         PANEL_NOTIFY_PROC, new_game_proc,
  99.         0);
  100.     suspend_item = panel_create_item(panel, PANEL_BUTTON,
  101.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Suspend", 9, buttonfont),
  102.         PANEL_NOTIFY_PROC, suspend_proc, 
  103.         0);
  104.     resume_item = panel_create_item(panel, PANEL_BUTTON,
  105.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Resume", 9, buttonfont),
  106.         PANEL_NOTIFY_PROC, resume_proc,
  107.         PANEL_SHOW_ITEM, FALSE,
  108.         PANEL_ITEM_X, panel_get(suspend_item, PANEL_ITEM_X), 
  109.         PANEL_ITEM_Y, panel_get(suspend_item ,PANEL_ITEM_Y), 
  110.         0);
  111.     level_item = panel_create_item(panel, PANEL_TEXT,
  112.         PANEL_LABEL_STRING, "Level:", 
  113.         PANEL_VALUE, "0",
  114.         (char *)PANEL_EVENT_PROC, (char *)no_events,
  115.         PANEL_VALUE_DISPLAY_LENGTH, 2,
  116.         0);
  117.     score_item = panel_create_item(panel, PANEL_TEXT,
  118.         PANEL_LABEL_STRING, "Score:", 
  119.         PANEL_VALUE, "0",
  120.         PANEL_VALUE_DISPLAY_LENGTH, 8,
  121.         (char *)PANEL_EVENT_PROC, (char *)no_events,
  122.         PANEL_VALUE_FONT, bigfont,
  123.         0);
  124.     interceptor_item = panel_create_item(panel, PANEL_SLIDER,
  125.         ATTR_LIST, panel_common,
  126. #ifdef STRINGLABELS
  127.         PANEL_LABEL_STRING, "Interceptors:     ",
  128. #else
  129.         PANEL_LABEL_IMAGE, &interceptor_pic,
  130. #endif
  131.         0);
  132.     rock_item = panel_create_item(panel, PANEL_SLIDER,
  133.         ATTR_LIST, panel_common,
  134. #ifdef STRINGLABELS
  135.         PANEL_LABEL_STRING, "Rocks:            ",
  136. #else
  137.         PANEL_LABEL_IMAGE, &rock_pic,
  138. #endif
  139.         0);
  140.     laser_item = panel_create_item(panel, PANEL_SLIDER,
  141.         ATTR_LIST, panel_common,
  142. #ifdef STRINGLABELS
  143.         PANEL_LABEL_STRING, "X-ray lasers:     ",
  144. #else
  145.         PANEL_LABEL_IMAGE, &laser_pic,
  146. #endif
  147.         0);
  148. #define FOE_WIDTH 270
  149.     foe_item = panel_create_item(panel, PANEL_SLIDER,
  150.         ATTR_LIST, panel_common,
  151. #ifdef STRINGLABELS
  152.         PANEL_LABEL_STRING, "Foe in flight:", 
  153. #else
  154.         PANEL_LABEL_IMAGE, &foe_pic,
  155. #endif
  156.         PANEL_SLIDER_WIDTH, FOE_WIDTH,
  157.         0);
  158.     total_foe_item = panel_create_item(panel, PANEL_TEXT,
  159.         PANEL_LABEL_STRING, "Total foe killed:", 
  160.         PANEL_VALUE, "0",
  161.         PANEL_VALUE_DISPLAY_LENGTH, 24,
  162.         (char *)PANEL_EVENT_PROC, (char *)no_events,
  163.         0);
  164.     if (time_to_play) {
  165.         timeout_item = panel_create_item(panel, PANEL_SLIDER,
  166.             ATTR_LIST, panel_common,
  167.             PANEL_LABEL_STRING, "Seconds remaining:", 
  168.             PANEL_MIN_VALUE, 0, PANEL_MAX_VALUE, time_to_play,
  169.             PANEL_VALUE, time_to_play,
  170.             PANEL_SLIDER_WIDTH, 500,
  171.             0);
  172.         continuous = 1;
  173.         start_timeout(timeout_item);
  174.     }
  175.     (void) panel_create_item(panel, PANEL_BUTTON,
  176.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Options", 9, buttonfont),
  177.         PANEL_NOTIFY_PROC, misc_options_proc,
  178.         0);
  179.     (void) panel_create_item(panel, PANEL_BUTTON,
  180.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Things to Read", 16, buttonfont),
  181.         PANEL_NOTIFY_PROC, text_options_proc,
  182.         0);
  183.     (void) panel_create_item(panel, PANEL_BUTTON,
  184.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Icon Options", 14, buttonfont),
  185.         PANEL_NOTIFY_PROC, icon_option_proc,
  186.         0);
  187.     skill_item = panel_create_item(panel, PANEL_CYCLE,
  188.         PANEL_LABEL_STRING, " Skill:",
  189.         PANEL_CHOICE_STRINGS, "Novice", "Occasional", "Expert", 0,
  190.         PANEL_NOTIFY_PROC, new_game_proc,
  191.         PANEL_VALUE, starting_skill,
  192.         0);
  193.     (void) panel_create_item(panel, PANEL_BUTTON,
  194.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Instructions", 14, buttonfont),
  195.         PANEL_NOTIFY_PROC, instructions_proc,
  196.         0);
  197.     if (gamemaster) {
  198.         (void) panel_create_item(panel, PANEL_TOGGLE,
  199.             PANEL_CHOICE_STRINGS, "Gamemaster", 0,
  200.             PANEL_NOTIFY_PROC, master_proc,
  201.             PANEL_SHOW_ITEM, TRUE,
  202.             0);
  203.     }
  204. }
  205.  
  206. void
  207. misc_options_proc()
  208. {
  209.     extern int cursor_type, ballistic_delay;
  210.     extern struct pixfont *buttonfont; /* use 'struct pixfont' for 3.0 compatiblity */
  211.     char *s;
  212.     Panel panel, make_popup_panel();
  213.     void options_done();
  214.     if ((panel = make_popup_panel("      SDI Options", options_done)) == NULL) {
  215.         return;
  216.     }
  217.  
  218.     (void) panel_create_item(panel, PANEL_CYCLE,
  219.         PANEL_LABEL_STRING, "Cursor:",
  220.         PANEL_CHOICE_IMAGES, &normal_pic, &dyna_pic, &cross_pic, &silly_pic, 0,
  221.         PANEL_MENU_CHOICE_STRINGS, "normal", "dynamic", "crosshair", "silly", 0,
  222.         PANEL_NOTIFY_PROC, cursor_notify_proc,
  223.         PANEL_VALUE, cursor_type,
  224.         0);
  225.     (void) panel_create_item(panel, PANEL_TOGGLE,
  226.         PANEL_CHOICE_STRINGS, "Non-stop", 0,
  227.         PANEL_NOTIFY_PROC, non_stop_notify_proc,
  228.         PANEL_VALUE, continuous,
  229.         0);
  230.     (void) panel_create_item(panel, PANEL_BUTTON,
  231.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Melt", 4, buttonfont),
  232.         PANEL_NOTIFY_PROC, end_proc,
  233.         0);
  234.     if (user_name[0] == '\0') {
  235.         s = (char *)get_name();
  236.         if (s[0] != '\0') strcpy(user_name, s);
  237.     }
  238.     user_name_item =  panel_create_item(panel, PANEL_TEXT,
  239.         PANEL_LABEL_STRING, "Name: ",
  240.         PANEL_VALUE_DISPLAY_LENGTH, 16,
  241.         PANEL_VALUE_STORED_LENGTH, 63,
  242.         PANEL_VALUE, user_name,
  243.         0);
  244.     panel_fit_width(panel);
  245.     (void) panel_create_item(panel, PANEL_BUTTON,
  246.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Save", 6, buttonfont),
  247.         PANEL_NOTIFY_PROC, save_proc,
  248.         0);
  249.     (void) panel_create_item(panel, PANEL_BUTTON,
  250.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Restore", 7, buttonfont),
  251.         PANEL_NOTIFY_PROC, restore_proc,
  252.         0);
  253.     save_file_item = panel_create_item(panel, PANEL_TEXT,
  254.         PANEL_LABEL_STRING, "Save file:",
  255.         PANEL_VALUE_DISPLAY_LENGTH, 16,
  256.         PANEL_VALUE_STORED_LENGTH, 63,
  257.         PANEL_VALUE, save_file_name,
  258.         0);
  259.     (void) panel_create_item(panel, PANEL_SLIDER,
  260.         PANEL_LABEL_STRING, "Cycle time (ms): ", 
  261.         PANEL_NOTIFY_LEVEL, PANEL_ALL,
  262.         PANEL_SLIDER_WIDTH, 100,
  263.         PANEL_MIN_VALUE, 50,
  264.         PANEL_MAX_VALUE, 250,
  265.         PANEL_SHOW_RANGE, FALSE,
  266.         PANEL_SHOW_VALUE, TRUE,
  267.         PANEL_VALUE, blast_delay/1000,
  268.         PANEL_SHOW_ITEM, TRUE,
  269.         PANEL_NOTIFY_PROC, cycle_time_proc,
  270.         0);
  271.     (void) panel_create_item(panel, PANEL_SLIDER,
  272.         PANEL_LABEL_STRING, "Ballistic time: ", 
  273.         PANEL_SLIDER_WIDTH, 50,
  274.         PANEL_MIN_VALUE, 0,
  275.         PANEL_MAX_VALUE, 10,
  276.         PANEL_SHOW_RANGE, FALSE,
  277.         PANEL_SHOW_VALUE, TRUE,
  278.         PANEL_VALUE, ballistic_delay,
  279.         PANEL_SHOW_ITEM, TRUE,
  280.         PANEL_NOTIFY_PROC, ballistic_time_proc,
  281.         0);
  282.     user_name[0] = '\0';
  283.     save_file_name[0] = '\0';
  284.     display_popup_panel(panel);
  285. }
  286.  
  287. void
  288. options_done()
  289. {
  290.     strcpy(user_name, panel_get_value(user_name_item));
  291.     strcpy(save_file_name, panel_get_value(save_file_item));
  292. }
  293.